class Solution {
    public:
        bool isValid(string s) {
                int i;
                    if (s.size() % 2 != 0)
                        return false;
                             stack<char> ch;
                                  for (i = 0; i< s.size(); i++)
                                       {
                                                if (s[i] == '(') ch.push(')');
                                                   else if (s[i] == '{') ch.push('}');
                                                      else if (s[i] == '[') ch.push(']');
                                                      else if (ch.empty() || ch.top() != s[i])
                                                           return false;         
                                                                    else ch.pop();  
                                       }
                                               return ch.empty();
        }
};